#include <iostream>

using namespace std;

const int MAXN = 1000;
int lch[MAXN], rch[MAXN];
char op[MAXN];
int nc;

int build_tree(char s[], int x, int y) {
    int c1 = -1, c2 = -1, p = 0;
    int u;
    if (y - x == 1) {
        u = ++nc;
        lch[u] = rch[u] = 0; op[u] = s[x];
        return u;
    }
    for (int i = x; i < y; ++i) {
        switch(s[i]) {
            case '(': ++p; break;
            case ')': --p; break;
            case '+': case '-':
                if (!p) c1 = i; break;
            case '*': case '/':
                if (!p) c2 = i; break;
        }
    }
    if (c1 < 0) c1 = c2;
    if (c1 < 0) return build_tree(s, x + 1, y - 1);
    u = ++nc;
    lch[u] = build_tree(s, x, c1);
    rch[u] = build_tree(s, c1 + 1, y);
    op[u] = s[c1];
    return u;
}

int main() {
    char s[]="a+b*(c-d)-e/f";
    build_tree(s, 0, 13);
    for (int i = 0; i < 13; ++i) cout << op[i] << ' ';
    cout << endl;
}

